home *** CD-ROM | disk | FTP | other *** search
/ ASME's Mechanical Engine…ing Toolkit 1997 December / ASME's Mechanical Engineering Toolkit 1997 December.iso / c_lang / z150_src.lzh / PRTERROR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-12  |  4.1 KB  |  124 lines

  1. #ifndef LINT
  2. static char sccsid[]="@(#) prterror.c 1.4 87/05/21 11:37:59";
  3. #endif /* LINT */
  4.  
  5. /*
  6. The contents of this file are hereby released to the public domain.
  7.  
  8.                                  -- Rahul Dhesi 1986/11/14
  9.  
  10. */
  11. #include "options.h"
  12. #include <stdio.h>      /* to make various.h includable */
  13. #include "various.h"
  14. /* General error handler.  Input format:
  15.  
  16.    parameter 1:  'w', 'e', or 'f'.
  17.  
  18.       'm':  message
  19.       'M':  message without preceding identification
  20.       'w':  WARNING
  21.       'e':  ERROR
  22.       'f':  FATAL
  23.       'F':  FATAL but program doesn't exist immediately
  24.  
  25.    All text printed is preceded by "Zoo:  " or "Ooz:  "  depending
  26.    upon conditional compilation, except in the case of 'M' messages
  27.    which are printed without any text being added.
  28.  
  29.    For messages, the text supplied is printed if and only if the global
  30.    variable "quiet" is zero.  Control then returns to the caller.
  31.  
  32.    For warnings, errors, and fatal errors, the variable "quiet" is ignored.
  33.  
  34.    For warnings and errors, the error message is preceded by the "WARNING:"
  35.    or "ERROR".  The error message is printed and control returns to the
  36.    caller.
  37.  
  38.    For fatal errors, the error message is preceded by "FATAL:" and an
  39.    error message is printed.  If the option was 'f', the program exits with 
  40.    a status of 1.  If the option was 'F', control returns to the caller and 
  41.    it is assumed that the caller will do any cleaning up necessary and then 
  42.    exit with an error status.
  43.  
  44.    parameter 2:  The format control string for printf.   
  45.    parameters 3 and 4 are passed along to printf.
  46.  
  47.    Note:  printf() is always supplied parameters 3 and 4, even if they were
  48.    not on the parameter list passed to prterror().  It is assumed that 
  49.    printf() will only use as many as are specified by the format string.
  50.    There is a small chance that on some machines, this will cause some
  51.    kind of stack exception (e.g. if the hardware maintains tag bits in
  52.    each word on the stack and doesn't allow certain types of data to
  53.    be arbitrarily accessed).  This is just a theory so far.
  54. */
  55.  
  56. extern int quiet;
  57.  
  58. /* These declarations must be equivalent to those in errors.i */
  59. char no_match[] = "No files matched.\n";
  60. char failed_consistency[] = "Archive header failed consistency check.\n";
  61. char invalid_header[] = "Invalid or corrupted archive.\n";
  62. char internal_error[]="Internal error.\n";
  63. char disk_full[]      = "I/O error or disk full.\n";
  64. char bad_directory[]  = "Directory entry in archive is invalid.\n";
  65. char no_memory[] = "Ran out of memory.\n";
  66. char too_many_files[] = "Some filenames ignored -- can only handle %d.\n";
  67.  
  68. #ifndef OOZ
  69. char wrong_version[]=
  70.    "Zoo %d.%d or later is needed to fully\nmanipulate this archive.\n";
  71. char cant_process[] = 
  72.    "The rest of the archive (%lu bytes) cannot be processed.\n";
  73. char option_ignored[] = "Ignoring option %c.\n";
  74. char inv_option[] = "Option %c is invalid.\n";
  75. char bad_crc[] = "\007Bad CRC, %s probably corrupted\n";
  76. #endif
  77.  
  78. #ifdef OOZ
  79. char could_not_open[] = "Could not open ";
  80. #else
  81. char could_not_open[] = "Could not open %s.\n";
  82. #endif
  83.  
  84. /*VARARGS2*/
  85. prterror(level, format, a, b, c)
  86. register int level;
  87. char *format, *a, *b, *c;
  88.  
  89. {
  90.    char string[120];       /* local format string */
  91.    *string = '\0';         /* get a null string to begin with */
  92.  
  93. #ifdef OOZ
  94.    strcpy (string, "Ooz:  ");
  95. #else
  96.    strcpy (string, "Zoo:  ");
  97. #endif
  98.  
  99.    switch (level) {
  100.       case 'M': *string = '\0';                    /* fall through to 'm' */
  101.       case 'm': if (quiet) return; break;
  102.       case 'w': strcat (string, "WARNING:  "); break;
  103.       case 'e': strcat (string, "ERROR:  ");   break;
  104.       case 'F':
  105.       case 'f': strcat (string, "FATAL:  ");   break;
  106.       default: prterror ('f', internal_error);  /* slick recursive call */
  107.    }
  108.  
  109.    strcat (string, format);      /* just append supplied message */
  110.  
  111. #ifdef OOZ
  112.    putstr (string);
  113.    putstr (a);
  114.    putstr (b);
  115. #else
  116.    printf (string, a, b, c);     /* and print the whole thing */
  117.     fflush (stdout);
  118. #endif
  119.  
  120.    if (level == 'f')       /* and abort on fatal error 'f' but not 'F' */
  121.       exit (1);
  122. }
  123.  
  124.